package com.jiajia.study.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

/**
 * @Title: RabbitDelayConfig
 * @Author zjj
 * @Package com.jiajia.study.config
 * @Date 2024/3/11 11:15
 * @description:    通过插件的方式实现延迟队列
 */


@Configuration
@Slf4j
public class RabbitDelayV2Config {


    @Bean
    public CustomExchange customExchange(){
        Map<String,Object> map = new HashMap<>();
        map.put("x-delayed-type","direct");
        return new CustomExchange("exchange.delay.v2","x-delayed-message",true,false,map);
    }

    @Bean
    public Queue queueDelayV2(){
        return QueueBuilder.durable("delay.queue.v2").build();
    }

    @Bean
    public Binding bindingDelayV2(CustomExchange customExchange,Queue queueDelayV2){
        return BindingBuilder.bind(queueDelayV2).to(customExchange).with("delayv2").noargs();
    }
}
